package ${pPackage}.service;

import ${pPackage}.pojo.${ClassName};
import ${pPackage}.mapper.${ClassName}Mapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (${ClassName})表服务实现类
 *
 * @author ${author}
 * @since ${createTime}
 */
@Service("${ClassName?uncap_first}Service")
public class ${ClassName}Service {
    @Resource
    private ${ClassName}Mapper ${ClassName?uncap_first}Mapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    public ${ClassName} queryById(${table.columns[0].columnType} id) {
        return this.${ClassName?uncap_first}Mapper.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    public List<${ClassName}> queryAllByLimit(int offset, int limit) {
        return this.${ClassName?uncap_first}Mapper.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param ${ClassName?uncap_first} 实例对象
     * @return 实例对象
     */
    public ${ClassName} insert(${ClassName} ${ClassName?uncap_first}) {
        this.${ClassName?uncap_first}Mapper.insert(${ClassName?uncap_first});
        return ${ClassName?uncap_first};
    }

    /**
     * 修改数据
     *
     * @param ${ClassName?uncap_first} 实例对象
     * @return 实例对象
     */
    public ${ClassName} update(${ClassName} ${ClassName?uncap_first}) {
        this.${ClassName?uncap_first}Mapper.update(${ClassName?uncap_first});
        return this.queryById(${ClassName?uncap_first}.get${table.columns[0].columnName2?cap_first}());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    public boolean deleteById(${table.columns[0].columnType} id) {
        return this.${ClassName?uncap_first}Mapper.deleteById(id) > 0;
    }
}